package com.ruoyix.weblog.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyix.weblog.domain.SrsCallbackRequest;
import com.ruoyix.weblog.domain.bo.BlogArticleBo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/auth")
public class AuthController {

    @SaIgnore
    @PostMapping("/publish")
    public String onPublish(@RequestBody SrsCallbackRequest request) {
        // 从回调请求中获取推流URL和Token
        String stream = request.getStream();
        String param = request.getParam();

         return "0";
    }

    @SaIgnore
    @PostMapping("/play")
    public ResponseEntity<String> handlePlay() {
        // 在这里添加你的鉴权逻辑
        boolean isAuthenticated = true;

        if (isAuthenticated) {
            return ResponseEntity.ok("允许播放");
        } else {
            return ResponseEntity.status(HttpStatus.FORBIDDEN).body("禁止播放");
        }
    }

    private boolean authenticateUser(String app, String stream, String ip) {
        // 实现具体的鉴权逻辑
        // 可以是检查数据库、Redis 中的信息，或者与第三方认证服务交互
        return true; // 示例中总是返回 true
    }
}
